﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Xml;
using Progetto.Beans.Filters;

namespace Progetto.Beans
{
    public class Friend : IRole
    {
        private string _name;
        private string _surname;
        private string _homeTown;
        private string _currentTown;
        private string _image; //ci metto l'URI della photo
        private Dictionary<string, MyCalendar> _calendars = new Dictionary<string, MyCalendar>(); //ho bisogno di indicizzare con il loro nome i calendari;
        private Dictionary<string, IFilterDescriptor> _filters = new Dictionary<string, IFilterDescriptor>(); //anche i filtri li indicizzo

     
        private string _emptyString = String.Empty;
        private MyCalendar _emptyCalendar = new MyCalendar("Calendario Personale");

        public Friend(string name, string surname) 
        {
            _name = name;
            _surname = surname;
            _calendars.Add(_emptyCalendar.Name, _emptyCalendar);
            
            _homeTown = _emptyString;
            _currentTown = _emptyString;
        }

        public Friend(string name, string surname, List<MyCalendar> calendars, string homeTown, string currentTown)
            : this(name, surname)
        {
            foreach (MyCalendar calendar in calendars)
            {
                _calendars.Add(calendar.Name, calendar);
            }
            _homeTown = homeTown;
            _currentTown = currentTown;
        }

        public Friend(XmlElement friend) 
        {
        
            _name = friend.GetAttribute("name");
            _surname = friend.GetAttribute("surname");
            _homeTown = friend.GetAttribute("homeTown");
            _currentTown = friend.GetAttribute("currentTown");
            _image = friend.GetAttribute("image");
            XmlNode calendarsNode = friend.SelectSingleNode("calendars");
            foreach (XmlNode calendarNode in calendarsNode.ChildNodes) 
            {
                XmlElement calendarElement = (XmlElement)calendarNode;
                MyCalendar calendar = new MyCalendar(calendarElement);
                _calendars.Add(calendar.Name, calendar);
            }
            XmlNode filtersNode = friend.SelectSingleNode("Filters");
            foreach (XmlNode filterNode in filtersNode.ChildNodes) 
            {
                XmlElement filterElement = (XmlElement)filterNode;
                if (filterElement.GetAttribute("filterType") == "Place Filter") 
                {
                    XmlElement placeFilterElement = (XmlElement)filterElement.SelectSingleNode("placeFilter");
                    PlaceFilterDescriptor placeFilter = new PlaceFilterDescriptor(placeFilterElement);
                    _filters.Add(placeFilter.Place, placeFilter); 
                }

                if (filterElement.GetAttribute("filterType") == "Friend Filter")
                {
                    XmlElement friendFilterElement = (XmlElement)filterElement.SelectSingleNode("friendFilter");
                    FriendFilterDescriptor friendFilter = new FriendFilterDescriptor(friendFilterElement);
                    _filters.Add(friendFilter.Email, friendFilter); 
                }

                if (filterElement.GetAttribute("filterType") == "Category Filter")
                {

                }

                if (filterElement.GetAttribute("filterType") == "Composite Filter")
                {

                }
            }
            
        }

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public string Surname
        {
            get { return _surname; }
            set { _surname = value; }
        }

        public string HomeTown
        {
            get { return _homeTown; }
            set { _homeTown = value; }
        }

        public string CurrentTown
        {
            get { return _currentTown; }
            set { _currentTown = value; }
        }

        public string Image
        {
            get { return _image; }
            set { _image = value; }
        }

        internal Dictionary<string, MyCalendar> Calendars
        {
            get { return _calendars; }
            set { _calendars = value; }
        }


        public Dictionary<string, IFilterDescriptor> Filters
        {
            get { return _filters; }
            set { _filters = value; }
        }

        public void AddCalendar(MyCalendar calendar)
        {
            throw new NotImplementedException();    
        }

        public void RemoveCalendar(MyCalendar calendar)
        {
            throw new NotImplementedException();
        }

        public void AddFilter(IFilterDescriptor filter) 
        {
            throw new NotImplementedException();
        }

        public void RemoveFilter(IFilterDescriptor filter)
        {
            throw new NotImplementedException();
        }


        #region IRole Members

        public string GetRoleName()
        {
            return "Friend";
        }

        #endregion
        
    }
}
